/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conn;
import java.sql.*;
import java.sql.ResultSetMetaData;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 * Realiza la conexión a la base de datos seleccionada.
 * @author Oscar Salazar
 */
public class Conn {
    
    public static String hostName;
    public static String port;
    public static String userName;
    public static String pass;
    public static String nameBD;
    public static Statement conn = null;
    
    /**
     * @return true /  false Si se puede realizar la conexion a la base de datos
     */
    public static boolean conn(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conection = DriverManager.getConnection("jdbc:mysql://"+hostName+":"+port+"/"+nameBD+"", userName, pass);
            conn = conection.createStatement();
            JOptionPane.showMessageDialog(null, "Conexión Base de datos - ok");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Conn.class.getName()).log(Level.SEVERE, null, ex);
             JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
             return false;
        } catch (SQLException ex) {
            Logger.getLogger(Conn.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
            return false;
        }
       
         return true; 
    } 
    
    /**
     * 
     * @return conn Conexion de la base de datos
     */
    public Statement getConn(){
        return conn;
    }
    
    /**
     * Función que se dan los parámetros de conexión de la base de datos.
     * @param hostName
     * @param nameBD
     * @param userName
     * @param pass 
     */
    public void setParametros(String hostName, String port, String nameBD, String userName, String pass){
        
        this.hostName = hostName;
        this.port = port;
        this.nameBD = nameBD;
        this.userName = userName;
        this.pass = pass;
    
    }
}
